#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

int is_space(char t)
{
    return (strchr(" \t\r\n", t) != NULL);
}

/* 此函数接受 %d %c %s \n 进行输入 */
int shiganfu(const char *format, void *ptr)
{
    enum { UNKNOWN, INT, CHAR, STR, SPACE} type = UNKNOWN;
    if (strcmp(format, "%d") == 0)
        type = INT;
    else if (strcmp(format, "%c") == 0)
        type = CHAR;
    else if (strcmp(format, "%s") == 0)
        type = STR;
    else if (strcmp(format, "\\n") == 0)
        type = SPACE;

    //printf("type = %d, format = %s\n", type, format);

    switch (type)
    {
        case INT:
        {
            int d = 0, c;
            while (c = getchar(), c != EOF && is_space(c)); //忽略空白
            if (c == EOF)
                return EOF;
            if (!isdigit(c)) {
                ungetc(c, stdin); //扔回给输入缓冲区
                return 0;
            }
            d = c - '0'; //第一个数字
            while (c = getchar(), c != EOF && isdigit(c))
            {
                d *= 10;
                d += c - '0';
            }
            if (c != EOF)
                ungetc(c, stdin); //扔回给输入缓冲区
            *(int *)ptr = d;
            return 1;
        }
        case CHAR:
        {
            int c = getchar();
            if (c == EOF)
                return EOF;
            *(char *)ptr = c;
            return 1;
        }
        case STR:
        {
            int c;
            char *p = (char *)ptr;
            while (c = getchar(), c != EOF)
                if (strchr(" \t\r\n", c) == NULL)
                    break;
            if (c == EOF)
                return EOF;
            *p++ = c;
            while (c = getchar(), c != EOF && !is_space(c))
            {
                *p++ = c;
            }
            *p = '\0';
            if (c != EOF)
                ungetc(c, stdin);
            return 1;
        }
        case SPACE:
        {
            int c;
            while (c = getchar(), c != EOF && is_space(c));
            if (c != EOF)
                ungetc(c, stdin);
            return 0;
        }
        default:
            fprintf(stderr, "unknown type\n");
            return 0;
    }
}

int main()
{
    char fmt[100];
    while (shiganfu("%s", fmt) == 1)
    {
        getchar();
        int ret;
        if (strcmp(fmt, "%d") == 0) {
            int d;
            ret = shiganfu(fmt, &d);
            printf("%d", ret);
            if (ret == 1)
                printf(" %d", d);
        }
        else if (strcmp(fmt, "%c") == 0) {
            int c;
            ret = shiganfu(fmt, &c);
            printf("%d", ret);
            if (ret == 1)
                printf(" %c", c);
        }
        else if (strcmp(fmt, "%s") == 0) {
            char s[110];
            ret = shiganfu(fmt, s);
            printf("%d", ret);
            if (ret == 1)
                printf(" %s", s);
        }
        else { // "\\n"
            shiganfu(fmt, NULL);
            printf("0");
        }
        printf("\n");
    }
    return 0;
}
